package top.wfzzq.ds.sort;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerializableDemo {
	public static void save(Student student, String file) throws Exception {
		// 对象输出流，可以将实现
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
		oos.writeObject(student);
		oos.close();
	}

	public static Student load(String file) throws Exception {
		// 对象输入流，可以将序列化到文件的对象还原回来
		ObjectInputStream ois=new  ObjectInputStream(new FileInputStream(file));
		Student student=(Student) ois.readObject();
		ois.close();
		return student;
	}

	public static void main(String[] args) {
		try {

//			SerializableDemo.save(new Student(100, "杨尚易"), "student.data");
//			System.out.println("输出到文件完成");
			
			System.out.println(SerializableDemo.load("student.data"));
			ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("demo.data"));
			oos.write(1234);
			System.out.println(Integer.toHexString(31));
			System.out.println(Integer.toBinaryString(31));
			//世界上
			System.out.println(Math.pow(3039, 3));
			System.out.println(Math.PI);
			System.out.println("============================");
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}
}
